home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 November / CPNL0711.ISO / boekhoud / finan / BADGER finance v1.0 beta 2.exe / xampplite / phpMyAdmin / libraries / Theme.class.php < prev    next >
PHP Script  |  2005-11-30  |  7KB  |  286 lines

  1. <?php
  2. /* $Id: Theme.class.php,v 1.5 2005/12/01 08:59:12 cybot_tm Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. class PMA_Theme {
  6.     /**
  7.      * @var string version
  8.      */
  9.     var $version = '0.0.0.0';
  10.  
  11.     /**
  12.      * @var string name
  13.      */
  14.     var $name = '';
  15.  
  16.     /**
  17.      * @var string id
  18.      */
  19.     var $id = '';
  20.  
  21.     /**
  22.      * @var string
  23.      */
  24.     var $path = '';
  25.  
  26.     /**
  27.      * @var string
  28.      */
  29.     var $img_path = '';
  30.  
  31.     /**
  32.      * @var array   valid css types
  33.      */
  34.     var $types = array( 'left', 'right', 'print' );
  35.  
  36.     /**
  37.      * @var integer last modification time for info file
  38.      */
  39.     var $mtime_info = 0;
  40.  
  41.     function __wakeup() {
  42.         $this->loadInfo();
  43.         $this->checkImgPath();
  44.     }
  45.  
  46.     function loadInfo() {
  47.         if ( ! file_exists( $this->getPath() . '/info.inc.php' ) ) {
  48.             return false;
  49.         }
  50.  
  51.         if ( $this->mtime_info === filemtime( $this->getPath() . '/info.inc.php' ) ) {
  52.             return true;
  53.         }
  54.  
  55.         @include( $this->getPath() . '/info.inc.php' );
  56.  
  57.         // did it set correctly?
  58.         if ( ! isset( $theme_name ) ) {
  59.             return false;
  60.         }
  61.  
  62.         $this->mtime_info = filemtime( $this->getPath() . '/info.inc.php' );
  63.  
  64.         if ( isset( $theme_full_version ) ) {
  65.             $this->setVersion( $theme_full_version );
  66.         } elseif ( isset( $theme_generation, $theme_version ) ) {
  67.             $this->setVersion( $theme_generation . '.' . $theme_version );
  68.         }
  69.         $this->setName( $theme_name );
  70.  
  71.         return true;
  72.     }
  73.  
  74.     /**
  75.      * returns theme object loaded from given folder
  76.      * or false if theme is invalid
  77.      *
  78.      * @static
  79.      * @param   string  path to theme
  80.      * @return  object  PMA_Theme
  81.      */
  82.     function load( $folder ) {
  83.  
  84.         $theme = new PMA_Theme();
  85.  
  86.         $theme->setPath( $folder );
  87.  
  88.         if ( ! $theme->loadInfo() ) {
  89.             return false;
  90.         }
  91.  
  92.         $theme->checkImgPath();
  93.  
  94.         return $theme;
  95.     }
  96.  
  97.     function checkImgPath() {
  98.         if ( is_dir( $this->getPath() . '/img/' ) ) {
  99.             $this->setImgPath( $this->getPath() . '/img/' );
  100.             return true;
  101.         } elseif ( is_dir( $GLOBALS['cfg']['ThemePath'] . '/original/img/' ) ) {
  102.             $this->setImgPath( $GLOBALS['cfg']['ThemePath'] . '/original/img/' );
  103.             return true;
  104.         } else {
  105.             $GLOBALS['PMA_errors'][] =
  106.                 sprintf( $GLOBALS['strThemeNoValidImgPath'], $this->getName() );
  107.             trigger_error(
  108.                 sprintf( $GLOBALS['strThemeNoValidImgPath'], $this->getName() ),
  109.                 E_USER_WARNING );
  110.             return false;
  111.         }
  112.     }
  113.  
  114.     /**
  115.      * returns path to theme
  116.      * @uses    $this->$path    as return value
  117.      * @return  string  $path   path to theme
  118.      */
  119.     function getPath() {
  120.         return $this->path;
  121.     }
  122.  
  123.     /**
  124.      * returns layout file
  125.      *
  126.      * @return  string  layout file
  127.      */
  128.     function getLayoutFile() {
  129.         return $this->getPath() . '/layout.inc.php';
  130.     }
  131.  
  132.     /**
  133.      * set path to theme
  134.      * @uses    $this->$path    to set it
  135.      * @param   string  $path   path to theme
  136.      */
  137.     function setPath( $path ) {
  138.         $this->path = trim( $path );
  139.     }
  140.  
  141.     /**
  142.      * sets version
  143.      * @uses    $this->version
  144.      * @param   string new version
  145.      */
  146.     function setVersion( $version ) {
  147.         $this->version = trim( $version );
  148.     }
  149.  
  150.     /**
  151.      * returns version
  152.      * @uses    $this->version
  153.      * @return  string  version
  154.      */
  155.     function getVersion() {
  156.         return $this->version;
  157.     }
  158.  
  159.     /**
  160.      * checks theme version agaisnt $version
  161.      * returns true if theme version is equal or higher to $version
  162.      *
  163.      * @uses    version_compare()
  164.      * @uses    $this->getVersion()
  165.      * @param   string  $version    version to compare to
  166.      * @return  boolean
  167.      */
  168.     function checkVersion( $version ) {
  169.         return version_compare( $this->getVersion(), $version, 'lt' );
  170.     }
  171.  
  172.     /**
  173.      * sets name
  174.      * @param   string  $name   new name
  175.      */
  176.     function setName( $name ) {
  177.         $this->name = trim( $name );
  178.     }
  179.  
  180.     /**
  181.      * returns name
  182.      * @return  string name
  183.      */
  184.     function getName() {
  185.         return $this->name;
  186.     }
  187.  
  188.     /**
  189.      * sets id
  190.      * @param   string  $id   new id
  191.      */
  192.     function setId( $id ) {
  193.         $this->id = trim( $id );
  194.     }
  195.  
  196.     /**
  197.      * returns id
  198.      * @return  string id
  199.      */
  200.     function getId() {
  201.         return $this->id;
  202.     }
  203.  
  204.     function setImgPath( $path ) {
  205.         $this->img_path = $path;
  206.     }
  207.  
  208.     function getImgPath() {
  209.         return $this->img_path;
  210.     }
  211.  
  212.     /**
  213.      * load css (send to stdout, normaly the browser)
  214.      *
  215.      * @uses    $this->getPath()
  216.      * @uses    $this->types
  217.      * @uses    PMA_SQP_buildCssData()
  218.      * @uses    file_exists()
  219.      * @uses    in_array()
  220.      * @param   string  $type   left, right or print
  221.      */
  222.     function loadCss( &$type ) {
  223.         if ( empty( $type ) || ! in_array( $type, $this->types ) ) {
  224.             $type = 'left';
  225.         }
  226.  
  227.         if ( $type == 'right' ) {
  228.             echo PMA_SQP_buildCssData();
  229.         }
  230.  
  231.         $_css_file = $this->getPath()
  232.                    . '/css/theme_' . $type . '.css.php';
  233.  
  234.         if ( file_exists( $_css_file ) ) {
  235.             if ( $GLOBALS['text_dir'] === 'ltr' ) {
  236.                 $right = 'right';
  237.                 $left = 'left';
  238.             } else {
  239.                 $right = 'left';
  240.                 $left = 'right';
  241.             }
  242.  
  243.             include( $_css_file );
  244.         }
  245.     }
  246.  
  247.     /**
  248.      * prints out the preview for this theme
  249.      *
  250.      * @uses    $this->getName()
  251.      * @uses    $this->getVersion()
  252.      * @uses    $this->getId()
  253.      * @uses    $this->getPath()
  254.      * @uses    $GLOBALS['strThemeNoPreviewAvailable']
  255.      * @uses    $GLOBALS['strTakeIt']
  256.      * @uses    PMA_generate_common_url()
  257.      * @uses    addslashes()
  258.      * @uses    file_exists()
  259.      * @uses    htmlspecialchars()
  260.      */
  261.     function printPreview() {
  262.         echo '<div class="theme_preview">';
  263.         echo '<h2>' . htmlspecialchars( $this->getName() )
  264.             .' (' . htmlspecialchars( $this->getVersion() ) . ')</h2>'
  265.             .'<p>'
  266.             .'<a target="_top" href="index.php'
  267.             .PMA_generate_common_url( array( 'set_theme' => $this->getId() ) ) . '"'
  268.             .' onclick="takeThis(\'' . addslashes( $this->getId() ) . '\');'
  269.             .' return false;">';
  270.         if ( @file_exists( $this->getPath() . '/screen.png' ) ) {
  271.             // if screen exists then output
  272.  
  273.             echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
  274.                 .' alt="' . htmlspecialchars( $this->getName() ) . '"'
  275.                 .' title="' . htmlspecialchars( $this->getName() ) . '" /><br />';
  276.         } else {
  277.             echo $GLOBALS['strThemeNoPreviewAvailable'];
  278.         }
  279.  
  280.         echo '[ <strong>' . $GLOBALS['strTakeIt'] . '</strong> ]</a>'
  281.             .'</p>'
  282.             .'</div>';
  283.     }
  284. }
  285.  
  286. ?>